﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using CefSharp;
using CefSharp.WinForms;
namespace print
{
    class Ptr30Event
    {
        public Dictionary<string, IJavascriptCallback> listeners = new Dictionary<string, IJavascriptCallback>();
        private ChromiumWebBrowser chrome;

        public Ptr30Event(ChromiumWebBrowser chrome)
        {
            this.chrome = chrome;
        }

        public void addEventListener(string listenerName, IJavascriptCallback callBackParam)
        {
            //OpenComplete
            Console.WriteLine(listenerName + "======listenerName=========");
            listeners[listenerName]= callBackParam;
        }
        public void open(string param)
        {
            Console.WriteLine(param + "======open=========");
            IJavascriptCallback callBack=listeners["OpenComplete"];
            if (callBack != null)
            {
                Dictionary<string, string> dict = new Dictionary<string, string>();
                dict.Add("result", "0");
                dict.Add("code", "open");
                callBack.ExecuteAsync(dict);
            }
        }
        public void reset(string param)
        {
            IJavascriptCallback callBack = listeners["ResetComplete"];
            if (callBack != null)
            {
                //responseEntity.code = "ptr30";
                //responseEntity.result = "0";
               
                callBack.ExecuteAsync("{hello}");
            }
        }
        public string getStatus(string param)
        {
            string jsonStr = "";
            return jsonStr;
        }
    }
}
